<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<style type="text/css">
	#add_goods_info3 .box label span {
		display: inline-block;
		width: 74px;
		text-align: right;
	}
	
	#add_goods_info3 .box label {
		margin-right: 20px;
	}
	
	#mainContent_content .formBox {
		padding: 0;
		position: relative;
	}
	
	#add_goods_info3 .formBox>div {
		padding: 20px;
	}
	
	#add_goods_info3 .uploadImg {
		width: 200px;
		position: absolute;
		top: 290px;
		left: 580px;
	}
	
	#add_goods_info3 .uploadImg .img {
		display: inline-block;
		width: 100px;
		height: 100px;
		background-color: #f5f5f5;
	}
	
	#add_goods_info3 .updateBox label span {
		width: 96px;
	}
</style>
<div class="modal fade" id="add_goods_info3" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document" style="width: 440px;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">角色修改</h4>
			</div>
			<form id="add_goods_form4">
				<div class="box modal-body">
					<p>
						<label>
						 <span class="must">角色名称</span> 
						 <input type="text" class="form-control"
							name="rolename" id="rolenames"></input>
						</label>
						<label> 
						<span class="must">角色状态</span>
						 <select class="form-control select" 
							id="roleStatus" name="status">
								<option value="启用" selected="selected">启用</option>
								<option value="关闭">关闭</option>
						</select>
						</label>

					</p>
				</div>

				<input type="hidden" name="roleid" id="roleid"> <input type="hidden" id="rolenames6">

			</form>
			<div class="red" id="add_goods_msg" style="text-align: center;"></div>
			<div class="modal-footer">
				<c:if test="${isEdit }">
					<button type="button" class="btn btn1" onclick="addRole8();">保存</button>
				</c:if>
				<button type="button" class="btn btn2" data-dismiss="modal">取消</button>
			</div>
		</div>
	</div>
</div>
<script>
	function updatesrole(id) {
		$.ajax({
			url: "<%=basePath%>role/getRoleById.do",
			type: "post",
			async: false,
			dataType: "json",
			data: "id=" + id,
			success: function(data) {
				$("#add_goods_form4 #rolenames").val(data.rolename);
				$("#add_goods_form4 #roleid").val(data.roleid);
				$("#add_goods_form4 #rolenames6").val(data.rolename);
				$("#add_goods_form4 #roleStatus option[value='" + data.status + "']").attr("selected", true);

				$('#add_goods_info3').modal('show');
			},
			error: function() {
				Prompt.alert("提示", "查询角色失败");
			}
		});

	}

	function addRole8() {
		var rolenames = document.getElementById("rolenames").value;
		var rolenames6 = document.getElementById("rolenames6").value;

		if(rolenames.length < 1) {
			Prompt.alert("提示", "请输入角色名称！");
			return;
		}

		var checksUserBoolean = "1";
		if(rolenames6 != rolenames.trim()) {
			checksUserBoolean = checkRole1();
		}

		if("1" == checksUserBoolean) {

			$.ajax({
				url: "<%=basePath%>role/updaterole.do",
				type: "post",
				async: false,
				dataType: "json",
				data: $("#add_goods_form4").serialize(),
				success: function(data) {
					if(data.result == "success") {
						location.href = location.href;
					} else {
						Prompt.alert("提示", "修改角色失败");
					}
				},
				error: function() {
					Prompt.alert("提示", "修改角色失败")
				}
			});
		}
	}
	/* 检查用户是否重复 */
	function checkRole1() {
		/* 0错，1对 */
		var result = "0";
		$.ajax({
			url: "<%=basePath%>role/checkRole.do",
			type: "post",
			async: false,
			dataType: "json",
			data: $("#add_goods_form4").serialize(),
			success: function(data) {
				if(data.result == "success") {
					result = "1";
				} else if(data.result == "fail") {
					Prompt.alert("提示", "角色名称重复，请重新命名");
				}
			},
			error: function() {
				Prompt.alert("提示", "检查角色名称是否重复失败")
			}
		});
		return result;
	}
</script>